/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.documentar.view;

import br.com.documentar.controller.ProdutoController;
import br.com.documentar.interfacee.InterfaceView;
import br.com.documentar.model.ProdutoModel;
import br.com.documentar.model.TabelaModel;
import br.com.documentar.util.UtilitariosCampos;
import br.com.documentar.util.setFiltroCampo;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;

/**
 *
 * @author Santos
 */
public class TabelaView extends javax.swing.JFrame implements InterfaceView<br.com.documentar.model.TabelaModel> {

    /**
     * *
     * Uma visão (view) pode ser qualquer saída de representação dos dados, como
     * uma tabela ou um diagrama. É possível ter várias visões do mesmo dado,
     * como um gráfico de barras para gerenciamento e uma visão tabular para
     * contadores.
     */
    private br.com.documentar.controller.TabelaController control = new br.com.documentar.controller.TabelaController();
    private br.com.documentar.model.TabelaModel model = control.getModel();

    /**
     * Creates new form ProdutoController
     */
    public TabelaView() {
        initComponents();
        Start();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabbedPaneManutencao = new javax.swing.JTabbedPane();
        panelConsulta = new javax.swing.JPanel();
        jLabelNome = new javax.swing.JLabel();
        textFieldConsultar = new javax.swing.JTextField();
        jScrollPanelConsulta = new javax.swing.JScrollPane();
        jTableConsulta = new javax.swing.JTable();
        panelAbaACadastro = new javax.swing.JPanel();
        jScrollPaneManutencaoA = new javax.swing.JScrollPane();
        jPanelManutencaoA = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        textFieldCodigo = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        textFieldNome = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        textAreaComentario = new javax.swing.JTextArea();
        jLabel5 = new javax.swing.JLabel();
        comboBoxProduto = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        textFieldNomeAmigavel = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        comboBoxTableSpace = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        comboBoxTemporaria = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        comboBoxDono = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        comboBoxAtivo = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        comboBoxTipoBanco = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        comboBoxNomeBanco = new javax.swing.JComboBox();
        panelAbaBCadastro = new javax.swing.JPanel();
        jScrollPaneManutencaoA1 = new javax.swing.JScrollPane();
        jPanelManutencaoB = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        textAreaSQL = new javax.swing.JTextArea();
        panelAbaRelatorio = new javax.swing.JPanel();
        toolBarManutencao = new javax.swing.JToolBar();
        buttonConsultar = new javax.swing.JButton();
        buttonNovo = new javax.swing.JButton();
        buttonEditar = new javax.swing.JButton();
        buttonExcluir = new javax.swing.JButton();
        buttonCancelar = new javax.swing.JButton();
        buttonGravar = new javax.swing.JButton();
        buttonRelatorio = new javax.swing.JButton();
        buttonAnterior = new javax.swing.JButton();
        buttonProximo = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastrar Tabela");

        jLabelNome.setText("Pesquisar:");

        jTableConsulta.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTableConsulta.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jTableConsulta.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTableConsulta.getTableHeader().setReorderingAllowed(false);
        jScrollPanelConsulta.setViewportView(jTableConsulta);

        javax.swing.GroupLayout panelConsultaLayout = new javax.swing.GroupLayout(panelConsulta);
        panelConsulta.setLayout(panelConsultaLayout);
        panelConsultaLayout.setHorizontalGroup(
            panelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelConsultaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelNome)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(textFieldConsultar, javax.swing.GroupLayout.DEFAULT_SIZE, 552, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jScrollPanelConsulta, javax.swing.GroupLayout.DEFAULT_SIZE, 626, Short.MAX_VALUE)
        );
        panelConsultaLayout.setVerticalGroup(
            panelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelConsultaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNome)
                    .addComponent(textFieldConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPanelConsulta, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE))
        );

        textFieldConsultar.getAccessibleContext().setAccessibleName("panelConsulta");
        textFieldConsultar.getAccessibleContext().setAccessibleDescription("");

        tabbedPaneManutencao.addTab("Consulta", panelConsulta);
        panelConsulta.getAccessibleContext().setAccessibleName("panelConsulta");

        jLabel1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel1.setText("Código:");

        textFieldCodigo.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));

        jLabel2.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel2.setText("Nome:");

        textFieldNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFieldNomeActionPerformed(evt);
            }
        });

        jLabel4.setText("Comentário:");

        textAreaComentario.setColumns(20);
        textAreaComentario.setRows(5);
        jScrollPane2.setViewportView(textAreaComentario);

        jLabel5.setText("Produto:");

        comboBoxProduto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER" }));

        jLabel3.setText("Nome Amigável:");

        jLabel6.setText("TableSpace");

        comboBoxTableSpace.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER", "SYSAUX", "SYSTEM", "TEMP", "TSD_APPUSER", "TSD_DBAUSER", "TSD_RBS", "TSD_TEMP", "TSI_DBAUSER" }));

        jLabel7.setText("Temporária:");

        comboBoxTemporaria.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER", "S - Sim", "N - Não" }));

        jLabel8.setText("Dono:");

        comboBoxDono.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER", "DBAUSER", "APPUSER", "WMSUSER", "BKPUSER", "EDIUSER", "SYSDBA", "REGISTRO" }));

        jLabel9.setText("Ativo:");

        comboBoxAtivo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER", "S - Sim", "N - Não" }));

        jLabel10.setText("Banco de Dados:");

        comboBoxTipoBanco.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER", "ORACLE", "FIREBIRD", "POSTGRE", "REGISTRO" }));

        jLabel11.setText("Nome do Banco:");

        comboBoxNomeBanco.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESCOLHER", "DBPROD", "DBSRV", "DBECF", "DBSEQ", "DBMOV", "NFE", "REGISTRO WINDOWS" }));

        javax.swing.GroupLayout jPanelManutencaoALayout = new javax.swing.GroupLayout(jPanelManutencaoA);
        jPanelManutencaoA.setLayout(jPanelManutencaoALayout);
        jPanelManutencaoALayout.setHorizontalGroup(
            jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelManutencaoALayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel5)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9))
                .addGap(79, 79, 79)
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textFieldNome)
                    .addComponent(textFieldNomeAmigavel)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanelManutencaoALayout.createSequentialGroup()
                        .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(textFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(comboBoxProduto, 0, 195, Short.MAX_VALUE)
                            .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(comboBoxTipoBanco, javax.swing.GroupLayout.Alignment.LEADING, 0, 195, Short.MAX_VALUE)
                                .addComponent(comboBoxNomeBanco, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(comboBoxTableSpace, 0, 192, Short.MAX_VALUE)
                                .addComponent(comboBoxTemporaria, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(comboBoxDono, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(comboBoxAtivo, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 249, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jPanelManutencaoALayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {comboBoxAtivo, comboBoxDono, comboBoxNomeBanco, comboBoxProduto, comboBoxTableSpace, comboBoxTemporaria, comboBoxTipoBanco});

        jPanelManutencaoALayout.setVerticalGroup(
            jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelManutencaoALayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(9, 9, 9)
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(comboBoxProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(textFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(textFieldNomeAmigavel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBoxTipoBanco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBoxNomeBanco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBoxTableSpace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBoxTemporaria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBoxDono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelManutencaoALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBoxAtivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelManutencaoALayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboBoxAtivo, comboBoxDono, comboBoxNomeBanco, comboBoxTableSpace, comboBoxTemporaria, comboBoxTipoBanco});

        jScrollPaneManutencaoA.setViewportView(jPanelManutencaoA);

        javax.swing.GroupLayout panelAbaACadastroLayout = new javax.swing.GroupLayout(panelAbaACadastro);
        panelAbaACadastro.setLayout(panelAbaACadastroLayout);
        panelAbaACadastroLayout.setHorizontalGroup(
            panelAbaACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneManutencaoA)
        );
        panelAbaACadastroLayout.setVerticalGroup(
            panelAbaACadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneManutencaoA, javax.swing.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
        );

        tabbedPaneManutencao.addTab("Pagina A", panelAbaACadastro);

        jLabel12.setText("SQL:");

        textAreaSQL.setColumns(20);
        textAreaSQL.setRows(5);
        jScrollPane1.setViewportView(textAreaSQL);

        javax.swing.GroupLayout jPanelManutencaoBLayout = new javax.swing.GroupLayout(jPanelManutencaoB);
        jPanelManutencaoB.setLayout(jPanelManutencaoBLayout);
        jPanelManutencaoBLayout.setHorizontalGroup(
            jPanelManutencaoBLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelManutencaoBLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 577, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelManutencaoBLayout.setVerticalGroup(
            jPanelManutencaoBLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelManutencaoBLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelManutencaoBLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(jPanelManutencaoBLayout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jScrollPaneManutencaoA1.setViewportView(jPanelManutencaoB);

        javax.swing.GroupLayout panelAbaBCadastroLayout = new javax.swing.GroupLayout(panelAbaBCadastro);
        panelAbaBCadastro.setLayout(panelAbaBCadastroLayout);
        panelAbaBCadastroLayout.setHorizontalGroup(
            panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneManutencaoA1)
        );
        panelAbaBCadastroLayout.setVerticalGroup(
            panelAbaBCadastroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneManutencaoA1, javax.swing.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
        );

        tabbedPaneManutencao.addTab("Pagina B", panelAbaBCadastro);

        javax.swing.GroupLayout panelAbaRelatorioLayout = new javax.swing.GroupLayout(panelAbaRelatorio);
        panelAbaRelatorio.setLayout(panelAbaRelatorioLayout);
        panelAbaRelatorioLayout.setHorizontalGroup(
            panelAbaRelatorioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 626, Short.MAX_VALUE)
        );
        panelAbaRelatorioLayout.setVerticalGroup(
            panelAbaRelatorioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 403, Short.MAX_VALUE)
        );

        tabbedPaneManutencao.addTab("Relatório", panelAbaRelatorio);

        toolBarManutencao.setFloatable(false);
        toolBarManutencao.setRollover(true);

        buttonConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_form_magnify.png"))); // NOI18N
        buttonConsultar.setMnemonic('l');
        buttonConsultar.setText("Consultar");
        buttonConsultar.setFocusable(false);
        buttonConsultar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonConsultar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonConsultarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonConsultar);

        buttonNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_add.png"))); // NOI18N
        buttonNovo.setMnemonic('N');
        buttonNovo.setText("Novo");
        buttonNovo.setFocusable(false);
        buttonNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonNovoActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonNovo);

        buttonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_edit.png"))); // NOI18N
        buttonEditar.setMnemonic('E');
        buttonEditar.setText("Editar");
        buttonEditar.setFocusable(false);
        buttonEditar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonEditar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonEditarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonEditar);

        buttonExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_delete.png"))); // NOI18N
        buttonExcluir.setMnemonic('x');
        buttonExcluir.setText("Excluir");
        buttonExcluir.setFocusable(false);
        buttonExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonExcluirActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonExcluir);

        buttonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/cancel.png"))); // NOI18N
        buttonCancelar.setMnemonic('C');
        buttonCancelar.setText("Cancelar");
        buttonCancelar.setFocusable(false);
        buttonCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCancelarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonCancelar);

        buttonGravar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/accept.png"))); // NOI18N
        buttonGravar.setMnemonic('a');
        buttonGravar.setText("Gravar");
        buttonGravar.setFocusable(false);
        buttonGravar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonGravar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonGravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonGravarActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonGravar);

        buttonRelatorio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/application_side_list.png"))); // NOI18N
        buttonRelatorio.setMnemonic('R');
        buttonRelatorio.setText("Relatório");
        buttonRelatorio.setFocusable(false);
        buttonRelatorio.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonRelatorio.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonRelatorio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonRelatorioActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonRelatorio);

        buttonAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/arrow_left.png"))); // NOI18N
        buttonAnterior.setMnemonic('o');
        buttonAnterior.setText("Anterior");
        buttonAnterior.setFocusable(false);
        buttonAnterior.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonAnterior.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAnteriorActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonAnterior);

        buttonProximo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/documentar/iconesManutencoes/arrow_right.png"))); // NOI18N
        buttonProximo.setMnemonic('m');
        buttonProximo.setText("Próximo");
        buttonProximo.setFocusable(false);
        buttonProximo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonProximo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buttonProximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonProximoActionPerformed(evt);
            }
        });
        toolBarManutencao.add(buttonProximo);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabbedPaneManutencao)
            .addComponent(toolBarManutencao, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(toolBarManutencao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tabbedPaneManutencao))
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void buttonConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConsultarActionPerformed
        Consultar();
    }//GEN-LAST:event_buttonConsultarActionPerformed

    private void buttonNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonNovoActionPerformed
        CarregarNovoDados();
    }//GEN-LAST:event_buttonNovoActionPerformed

    private void buttonEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonEditarActionPerformed
        CarregarEditarDados();
    }//GEN-LAST:event_buttonEditarActionPerformed

    private void buttonExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExcluirActionPerformed
        CarregarExcluirDados();
    }//GEN-LAST:event_buttonExcluirActionPerformed

    private void buttonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelarActionPerformed
        CancelarOperacao();
    }//GEN-LAST:event_buttonCancelarActionPerformed

    private void buttonGravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGravarActionPerformed
        GravarDados();
    }//GEN-LAST:event_buttonGravarActionPerformed

    private void buttonRelatorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRelatorioActionPerformed
        tabbedPaneManutencao.setSelectedIndex(2);
    }//GEN-LAST:event_buttonRelatorioActionPerformed

    private void buttonAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAnteriorActionPerformed
        ProximaAba("Anterior");
    }//GEN-LAST:event_buttonAnteriorActionPerformed

  private void buttonProximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProximoActionPerformed
      ProximaAba("Proximo");
  }//GEN-LAST:event_buttonProximoActionPerformed

    private void textFieldNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFieldNomeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textFieldNomeActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main() {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TabelaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TabelaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TabelaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TabelaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TabelaView().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonAnterior;
    private javax.swing.JButton buttonCancelar;
    protected javax.swing.JButton buttonConsultar;
    private javax.swing.JButton buttonEditar;
    private javax.swing.JButton buttonExcluir;
    private javax.swing.JButton buttonGravar;
    private javax.swing.JButton buttonNovo;
    private javax.swing.JButton buttonProximo;
    private javax.swing.JButton buttonRelatorio;
    private javax.swing.JComboBox comboBoxAtivo;
    private javax.swing.JComboBox comboBoxDono;
    private javax.swing.JComboBox comboBoxNomeBanco;
    private javax.swing.JComboBox comboBoxProduto;
    private javax.swing.JComboBox comboBoxTableSpace;
    private javax.swing.JComboBox comboBoxTemporaria;
    private javax.swing.JComboBox comboBoxTipoBanco;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelNome;
    private javax.swing.JPanel jPanelManutencaoA;
    private javax.swing.JPanel jPanelManutencaoB;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPaneManutencaoA;
    private javax.swing.JScrollPane jScrollPaneManutencaoA1;
    private javax.swing.JScrollPane jScrollPanelConsulta;
    private javax.swing.JTable jTableConsulta;
    private javax.swing.JPanel panelAbaACadastro;
    private javax.swing.JPanel panelAbaBCadastro;
    private javax.swing.JPanel panelAbaRelatorio;
    private javax.swing.JPanel panelConsulta;
    private javax.swing.JTabbedPane tabbedPaneManutencao;
    private javax.swing.JTextArea textAreaComentario;
    private javax.swing.JTextArea textAreaSQL;
    private javax.swing.JTextField textFieldCodigo;
    private javax.swing.JTextField textFieldConsultar;
    private javax.swing.JTextField textFieldNome;
    private javax.swing.JTextField textFieldNomeAmigavel;
    private javax.swing.JToolBar toolBarManutencao;
    // End of variables declaration//GEN-END:variables

    @Override
    public void CarregarEditarDados() {
        model.setActionScript("U");
        if (jTableConsulta.getSelectedRow() != -1) {
            TabelaModel tabelaModel = model.getTabela(Integer.parseInt(jTableConsulta.getValueAt(jTableConsulta.getSelectedRow(), 0).toString()));

            textFieldCodigo.setText(String.valueOf(tabelaModel.getCodigo()));
            comboBoxProduto.setSelectedItem(tabelaModel.getProduto().getCodigo() + " - " + tabelaModel.getProduto().getNome());
            textFieldNome.setText(tabelaModel.getNome());
            textFieldNomeAmigavel.setText(tabelaModel.getNomeAmigavel());
            textAreaComentario.setText(tabelaModel.getComentario());
            comboBoxTableSpace.setSelectedItem(tabelaModel.getTableSpace());
            comboBoxTemporaria.setSelectedItem(tabelaModel.getTemporaria() == 'S' ? "S - Sim" : "N - Não");
            comboBoxDono.setSelectedItem(tabelaModel.getDono());
            comboBoxAtivo.setSelectedItem(tabelaModel.getAtivo() == 'S' ? "S - Sim" : "N - Não");
            comboBoxTipoBanco.setSelectedItem(tabelaModel.getTipoBanco());
            comboBoxNomeBanco.setSelectedItem(tabelaModel.getNomeBanco());
            textAreaSQL.setText(tabelaModel.getSqlTextArea());

            tabbedPaneManutencao.setSelectedIndex(1);
            textFieldNome.requestFocus();
            textFieldCodigo.setEnabled(false);
        } else {
            JOptionPane.showMessageDialog(rootPane, "Nenhuma linha selecionada");
        }
    }

    @Override
    public void CarregarNovoDados() {
        model.setActionScript("I");
        textFieldCodigo.setEnabled(false);
        tabbedPaneManutencao.setSelectedIndex(1);
        textFieldNome.requestFocus();
    }

    @Override
    public void CarregarExcluirDados() {
        if (jTableConsulta.getSelectedRow() != -1) {
            TabelaModel tabelaModel = model.getTabela(Integer.parseInt(jTableConsulta.getValueAt(jTableConsulta.getSelectedRow(), 0).toString()));
            tabelaModel.setActionScript("D");
            control.setDados(tabelaModel);
        } else {
            JOptionPane.showMessageDialog(rootPane, "Nenhuma linha selecionada");
        }
        Consultar();
    }

    @Override
    public void GravarDados() {
        if (model.getActionScript().equals("I") || model.getActionScript().equals("U")) {
            if (ValidaCampos()) {
                CarregarVariaveis();
                if (model.getActionScript().equals("I") && model.getTabela(model.getCodigo()) != null) {
                    JOptionPane.showMessageDialog(panelConsulta, "Item já cadastrado na base de dados.");
                } else {
                    if (control.setDados(model)) {
                        Consultar();
                        LimparCampos();
                    }
                }
            }
        } else {
            JOptionPane.showMessageDialog(panelConsulta, "Você deve escolher uma ação clicando no botão Novo ou Editar.");
        }
    }

    @Override
    public void LimparCampos() {
        UtilitariosCampos.getLimpezaCampos(tabbedPaneManutencao);
    }

    @Override
    public void ProximaAba(String Movimento) {
        int a = tabbedPaneManutencao.getSelectedIndex();
        int quantidadeAba = tabbedPaneManutencao.getTabCount() - 1;
        switch (Movimento) {
            case "Anterior":
                if (a != 0) {
                    tabbedPaneManutencao.setSelectedIndex(a - 1);
                }
                break;
            case "Proximo":
                if (a != quantidadeAba) {
                    tabbedPaneManutencao.setSelectedIndex(a + 1);
                }
                break;
        }
    }

    @Override
    public void TamanhoColunaTable() {
        jTableConsulta.getColumnModel().getColumn(0).setMinWidth(10);//código 
        jTableConsulta.getColumnModel().getColumn(0).setPreferredWidth(60);
        jTableConsulta.getColumnModel().getColumn(0).setMaxWidth(100);

        jTableConsulta.getColumnModel().getColumn(1).setMinWidth(30);//PRODUTO
        jTableConsulta.getColumnModel().getColumn(1).setPreferredWidth(270);
        jTableConsulta.getColumnModel().getColumn(1).setMaxWidth(600);

        jTableConsulta.getColumnModel().getColumn(2).setMinWidth(30);//nome
        jTableConsulta.getColumnModel().getColumn(2).setPreferredWidth(300);
        jTableConsulta.getColumnModel().getColumn(2).setMaxWidth(999);

        jTableConsulta.getColumnModel().getColumn(3).setMinWidth(30);//nome amigável
        jTableConsulta.getColumnModel().getColumn(3).setPreferredWidth(300);
        jTableConsulta.getColumnModel().getColumn(3).setMaxWidth(999);

        jTableConsulta.getColumnModel().getColumn(4).setMinWidth(30);//comentário
        jTableConsulta.getColumnModel().getColumn(4).setPreferredWidth(300);
        jTableConsulta.getColumnModel().getColumn(4).setMaxWidth(999);

        jTableConsulta.getColumnModel().getColumn(5).setMinWidth(30);//tablespace
        jTableConsulta.getColumnModel().getColumn(5).setPreferredWidth(100);
        jTableConsulta.getColumnModel().getColumn(5).setMaxWidth(500);

        jTableConsulta.getColumnModel().getColumn(6).setMinWidth(30);//temporario
        jTableConsulta.getColumnModel().getColumn(6).setPreferredWidth(100);
        jTableConsulta.getColumnModel().getColumn(6).setMaxWidth(500);

        jTableConsulta.getColumnModel().getColumn(7).setMinWidth(30);//dono
        jTableConsulta.getColumnModel().getColumn(7).setPreferredWidth(100);
        jTableConsulta.getColumnModel().getColumn(7).setMaxWidth(500);

        jTableConsulta.getColumnModel().getColumn(8).setMinWidth(30);//ativo
        jTableConsulta.getColumnModel().getColumn(8).setPreferredWidth(100);
        jTableConsulta.getColumnModel().getColumn(8).setMaxWidth(500);

        jTableConsulta.getColumnModel().getColumn(9).setMinWidth(30);//Tipo Banco
        jTableConsulta.getColumnModel().getColumn(9).setPreferredWidth(100);
        jTableConsulta.getColumnModel().getColumn(9).setMaxWidth(500);

        jTableConsulta.getColumnModel().getColumn(10).setMinWidth(30);//Nome Banco
        jTableConsulta.getColumnModel().getColumn(10).setPreferredWidth(100);
        jTableConsulta.getColumnModel().getColumn(10).setMaxWidth(500);

        jTableConsulta.getColumnModel().getColumn(11).setMinWidth(30);//SQL
        jTableConsulta.getColumnModel().getColumn(11).setPreferredWidth(600);
        jTableConsulta.getColumnModel().getColumn(11).setMaxWidth(999);
    }

    @Override
    public void Consultar() {
        model.setActionScript("C");
        jTableConsulta.setModel(control.getDadosTableModel(model));
        tabbedPaneManutencao.setSelectedIndex(0);
        textFieldConsultar.requestFocus();
        TamanhoColunaTable();
    }

    @Override
    public void CommitCampos() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void CancelarOperacao() {
        LimparCampos();
        Consultar();
    }

    /**
     * Carregar variaveis para gravação dos dados
     */
    @Override
    public void CarregarVariaveis() {
        model.setCodigo(UtilitariosCampos.getIntegerText(textFieldCodigo));
        model.getProduto().setCodigo(UtilitariosCampos.getIntegerComboBox(comboBoxProduto));
        model.setNome(textFieldNome.getText().toString());
        model.setComentario(textAreaComentario.getText().toString());
        model.setNomeAmigavel(textFieldNomeAmigavel.getText().toString());
        model.setTableSpace(comboBoxTableSpace.getSelectedItem().toString());
        model.setTemporaria(UtilitariosCampos.getRespostaComboBox(comboBoxTemporaria));
        model.setDono(comboBoxDono.getSelectedItem().toString());
        model.setAtivo(UtilitariosCampos.getRespostaComboBox(comboBoxAtivo));
        model.setTipoBanco(comboBoxTipoBanco.getSelectedItem().toString());
        model.setNomeBanco(comboBoxNomeBanco.getSelectedItem().toString());
        model.setSql(textAreaSQL.getText());
    }

    KeyAdapter pesquisaDados = new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {

            switch (e.getKeyCode()) {
                case KeyEvent.VK_ENTER://Botão Enter
                    model.setNome(textFieldConsultar.getText());
                    model.setActionScript("P");
                    jTableConsulta.setModel(control.getDadosTableModel(model));
                    TamanhoColunaTable();
                    break;
            }
        }
    };

    @Override
    public void InicializarListener() {
        //Adicionar escutado ao componente
        textFieldConsultar.addKeyListener(pesquisaDados);

    }

    @Override
    public void Start() {
        Consultar();
        InicializarListener();
        setExtendedState(MAXIMIZED_BOTH);
        model.setNomeTela(getTitle());
        setFiltroCampo();
        CarregarDadosComboBox(model, null);
    }

    @Override
    public boolean ValidaCampos() {
        if (!UtilitariosCampos.getValidarCampos(jPanelManutencaoA)) {
            tabbedPaneManutencao.setSelectedIndex(1);
            return false;
        } else if (!UtilitariosCampos.getValidarCampos(jPanelManutencaoB)) {
            tabbedPaneManutencao.setSelectedIndex(2);
            return false;
        } else {
            return true;
        }
    }

    @Override
    public void CarregarDadosComboBox(TabelaModel model, String actionScript) {
        ProdutoController produtoControl = new ProdutoController();
        ProdutoModel produtoModel = produtoControl.getModel();
        produtoModel.setActionScript("C");
        comboBoxProduto.setModel(produtoControl.getDadosComboBoxModel(produtoModel));

    }

    @Override
    public void setFiltroCampo() {
        textFieldConsultar.setDocument(new setFiltroCampo(50, "LetraNumeroRealEspaco"));
        textFieldNome.setDocument(new setFiltroCampo(100, "ObjetoBanco"));
        textFieldNomeAmigavel.setDocument(new setFiltroCampo(50, "LetraNumeroRealEspaco"));
        textAreaComentario.setDocument(new setFiltroCampo(65535, "Texto", 'P'));
        textAreaSQL.setDocument(new setFiltroCampo(429496729, "Texto", 'P'));

    }
}
